package com.ruoyi.web.controller.tool;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysWorkRoom;
import com.ruoyi.system.service.ISysWorkRoomService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车间信息Controller
 * 
 * @author spark
 * @date 2023-07-23
 */
@ApiOperation("车间信息管理")
@RestController
@RequestMapping("/test/room")
@Anonymous
public class TestWorkRoomController extends BaseController
{
    @Autowired
    private ISysWorkRoomService sysWorkRoomService;

    /**
     * 查询车间信息列表
     */
    @ApiOperation("查询车间信息列表")
    @GetMapping("/list")
    public TableDataInfo list(SysWorkRoom sysWorkRoom)
    {
        startPage();
        List<SysWorkRoom> list = sysWorkRoomService.selectSysWorkRoomList(sysWorkRoom);
        return getDataTable(list);
    }

    /**
     * 导出车间信息列表
     */
    @Log(title = "车间信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysWorkRoom sysWorkRoom)
    {
        List<SysWorkRoom> list = sysWorkRoomService.selectSysWorkRoomList(sysWorkRoom);
        ExcelUtil<SysWorkRoom> util = new ExcelUtil<SysWorkRoom>(SysWorkRoom.class);
        util.exportExcel(response, list, "车间信息数据");
    }

    /**
     * 获取车间信息详细信息
     */
    @ApiOperation("获取车间信息详细信息")
    @GetMapping(value = "/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId)
    {
        return success(sysWorkRoomService.selectSysWorkRoomByRoomId(roomId));
    }

    /**
     * 新增车间信息
     */
    @ApiOperation("新增车间信息")
    @Log(title = "车间信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysWorkRoom sysWorkRoom)
    {
        return toAjax(sysWorkRoomService.insertSysWorkRoom(sysWorkRoom));
    }

    /**
     * 修改车间信息
     */
    @ApiOperation("修改车间信息")
    @Log(title = "车间信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWorkRoom sysWorkRoom)
    {
        return toAjax(sysWorkRoomService.updateSysWorkRoom(sysWorkRoom));
    }

    /**
     * 删除车间信息
     */
    @ApiOperation("删除车间信息")
    @Log(title = "车间信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roomIds}")
    public AjaxResult remove(@PathVariable Long[] roomIds)
    {
        return toAjax(sysWorkRoomService.deleteSysWorkRoomByRoomIds(roomIds));
    }
}
